package com.zdsoft.blp.zongbuju.shouye.linliquan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.imageTrans.CircleImage;
import com.zdsoft.blp.zongbuju.shouye.linliquan.entity.LinLi;
import com.zdsoft.blp.zongbuju.shouye.linliquan.entity.PinCheEntity;

import java.util.List;

/**
 * Created by Administrator on 2016/8/31.
 */
public class PinCheXinXiAdapter extends BaseAdapter {
    private List<PinCheEntity> list;
    private LayoutInflater inflater;
    private Context context;

    public PinCheXinXiAdapter(List<PinCheEntity> list, Context context) {
        this.list = list;
        this.context = context;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView=inflater.inflate(R.layout.linli_pinche_item,null);
            holder=new ViewHolder();
            holder.pc_name= (TextView) convertView.findViewById(R.id.pc_name);
            holder.pc_title_time= (TextView) convertView.findViewById(R.id.pc_title_time);
            holder.pc_qidian= (TextView) convertView.findViewById(R.id.pc_qidian);
            holder.pc_zhongdian= (TextView) convertView.findViewById(R.id.pc_zhongdian);
            holder.pc_time= (TextView) convertView.findViewById(R.id.pc_time);
            holder.pc_lianxiren= (TextView) convertView.findViewById(R.id.pc_lianxiren);
            holder.pc_dianhua= (TextView) convertView.findViewById(R.id.pc_dianhua);
            holder.pc_cheliang= (TextView) convertView.findViewById(R.id.pc_cheliang);
            holder.pc_miaoshu= (TextView) convertView.findViewById(R.id.pc_miaoshu);
            holder.pc_iv= (ImageView) convertView.findViewById(R.id.pc_iv);
            holder.ll_shenhe= (LinearLayout) convertView.findViewById(R.id.ll_shenhe);
            holder.tv_delete= (TextView) convertView.findViewById(R.id.tv_delete);
            holder.iv_shenhe= (ImageView) convertView.findViewById(R.id.iv_shenhe);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        PinCheEntity user=list.get(position);
        if (user.getCode()==2){
            holder.pc_name.setText(user.getUsername());
            holder.pc_qidian.setText(user.getQidian());
            holder.pc_zhongdian.setText(user.getZhongdian());
            holder.pc_title_time.setText(user.getcDate());
            holder.pc_time.setText(user.getTime());
            holder.pc_lianxiren.setText(user.getLianXR());
            holder.pc_dianhua.setText(user.getLianXDH());
            holder.pc_cheliang.setText(user.getCheLMS());
            holder.pc_miaoshu.setText(user.getMiaoS());
            holder.ll_shenhe.setVisibility(View.VISIBLE);
            switch (user.getApprovedResult()){
                case -1:
                    Picasso.with(context).load(R.drawable.shz).into(holder.iv_shenhe);
                    break;
                case 0:
                    Picasso.with(context).load(R.drawable.shwtg).into(holder.iv_shenhe);
                    break;
                case 1:
                    Picasso.with(context).load(R.drawable.shtg).into(holder.iv_shenhe);
                    break;
            }
        }else {
            holder.pc_name.setText(user.getUsername());
            holder.pc_qidian.setText(user.getQidian());
            holder.pc_zhongdian.setText(user.getZhongdian());
            holder.pc_title_time.setText(user.getcDate());
            holder.pc_time.setText(user.getTime());
            holder.pc_lianxiren.setText(user.getLianXR());
            holder.pc_dianhua.setText(user.getLianXDH());
            holder.pc_cheliang.setText(user.getCheLMS());
            holder.pc_miaoshu.setText(user.getMiaoS());
        }

        if (!"".equals(user.getTouxiang())){
            Picasso.with(context).load(user.getTouxiang()).transform(new CircleImage()).into(holder.pc_iv);
        }
        return convertView;
    }
    class ViewHolder{
        TextView pc_qidian,pc_zhongdian,pc_time,pc_lianxiren,pc_dianhua,pc_cheliang,
                pc_miaoshu,pc_title_time,pc_name,tv_delete;
        ImageView pc_iv,iv_shenhe;
        LinearLayout ll_shenhe;
    }
    public List<PinCheEntity> setListData(List<PinCheEntity> list){
        return this.list=list;
    }
}
